export function formatTimeDiff(timestamp) {
	const now = Date.now();
	const diff = now - timestamp; // 时间差（毫秒）

	if (diff < 0) {
		return null; // 处理未来时间戳
	}

	const seconds = Math.floor(diff / 1000);
	const minutes = Math.floor(seconds / 60);
	const hours = Math.floor(minutes / 60);
	const days = Math.floor(hours / 24);

	// 计算月份差异（近似值）
	const startDate = new Date(timestamp);
	const currentDate = new Date(now);
	const monthDiff = (currentDate.getFullYear() - startDate.getFullYear()) * 12 +
		(currentDate.getMonth() - startDate.getMonth());

	if (seconds < 60) {
		return '1分钟'; // 1分钟内显示1分钟
	} else if (minutes < 60) {
		return `${minutes}分钟`; // 1小时内显示分钟数
	} else if (hours < 24) {
		return `${hours}小时`; // 1天内显示小时数
	} else if (days <= 30) {
		return `${days}天`; // 1月内显示天数
	} else if (monthDiff <= 3) {
		return `${monthDiff}个月`; // 3月内显示月数
	} else {
		return null; // 超过3个月返回null
	}
}


export function gotoHome() {
	uni.showModal({
		title: "提示",
		content: "页面有误将返回首页",
		showCancel: false,
		success: (res) => {
			if (res.confirm) {
				uni.reLaunch({
					url: "/pages/index/index"
				})
			}
		}
	})
}